package cn.tedu.ivos.dictoption.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.dict.pojo.dto.DictSaveParam;
import cn.tedu.ivos.dictoption.pojo.dto.DictOptionQuery;
import cn.tedu.ivos.dictoption.pojo.dto.DictOptionSaveParam;
import cn.tedu.ivos.dictoption.pojo.vo.DictOptionVO;
import cn.tedu.ivos.dictoption.service.DictOptionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.json.Json;

import java.util.List;

@RestController
@RequestMapping("v1/dictOption")
@Slf4j
public class DictOptionController {
    @Autowired
    DictOptionService dictOptionService;
    @GetMapping("select")
    public JsonResult selectDictOption (DictOptionQuery dictOptionQuery){
        log.debug("字典项查询,参数{}",dictOptionQuery);
        List<DictOptionVO> list = dictOptionService.selectDictOption(dictOptionQuery);
        return JsonResult.ok(list);
    }
    @PostMapping("save")
    public JsonResult saveDictOption(DictOptionSaveParam dictOptionSaveParam){
        log.debug("字典保存,参数{}",dictOptionSaveParam);
        dictOptionService.saveDictOption(dictOptionSaveParam);
        return JsonResult.ok();
    }
    @PostMapping("delete/{id}")
    public JsonResult deleteDictOption(@PathVariable Long id){
        log.debug("字典项删除,参数{}",id);
        dictOptionService.deleteDictOption(id);
        return JsonResult.ok();
    }
    /* 定义一个根据字典code查询该字典下所有字典项的方法*/
    @GetMapping("select/{code}")
    public JsonResult selectDictOptionByCode(@PathVariable String code){
        log.debug("根据字典code查询该字典下所有字典项,参数{}",code);
        List<DictOptionVO> list = dictOptionService.selectDictOptionByCode(code);
        return JsonResult.ok(list);
    }
}
